
package com.xtsoft.platform.report.service.impl;


/*
*    上海信拓信息技术有限公司 Koala企业综合信息管理系统
*    Copyright (C) 2010-2015 ShangHai XinTuo Software Inc.
*/
import com.xtsoft.core.service.impl.GenericServiceImpl;
import com.xtsoft.platform.base.system.domain.SysResource;
import com.xtsoft.platform.base.system.repository.SysResourceRepository;
import com.xtsoft.platform.globe.enums.YesNo;
import com.xtsoft.platform.report.domain.RepDefine;
import com.xtsoft.platform.report.repository.RepDefineRepository;
import com.xtsoft.platform.report.repository2.RepDefineRepository2;
import com.xtsoft.platform.report.service.RepDefineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xtsoft.core.utils.ResultMsg;

import java.util.List;

@Service("repDefineService")
public class RepDefineServiceImpl extends GenericServiceImpl<RepDefine,String, RepDefineRepository2> implements RepDefineService {

	@Autowired
	public RepDefineRepository repDefineRepository;
	@Autowired
	public SysResourceRepository sysResourceRepository;
	@Override
	public RepDefine orderByobjCode() {
		// TODO Auto-generated method stub
		return repDefineRepository.orderByobjCode();
	}
	@Override
	public ResultMsg savePublish(RepDefine repDefine, String preResourceId, String resourceName, String resourceId,
			String descript) {
		// TODO Auto-generated method stub
		SysResource resource = sysResourceRepository.findByResourceId(resourceId);
		if(resource != null) {
			return new ResultMsg(false,"资源ID【"+resourceId+"】已存在！禁止添加！");
		}
		SysResource sysResource = new SysResource();
		sysResource.setResourceId(resourceId);
		sysResource.setPreResourceId(preResourceId);
		sysResource.setResourceNick(resourceName);
		sysResource.setResourceName(resourceName);
		sysResource.setButtonClr("soft-blue");
		sysResource.setDescript(descript);
		sysResource.setIconClsId("x-fa fa-bar-chart");
		sysResource.setIsDesktop(YesNo.No.getIntValue());
		sysResource.setIsPublic(YesNo.No.getIntValue());
		sysResource.setState(YesNo.Yes.getIntValue());
		sysResource.setResourceType(YesNo.Yes.getIntValue());
		sysResource.setIsQuickLaunch(YesNo.No.getIntValue());
		//计算 排序号
		List<SysResource> list = sysResourceRepository.findByPreResourceId(preResourceId);
		if(list.size() > 0){
			sysResource.setSerialNo(list.size() + 1);
		}else{
			sysResource.setSerialNo(1);
		}
		sysResource.setAttachMethod("doReport");
		sysResource.setResourceUrl(repDefine.getObjCode());
		repDefine.setState(YesNo.Yes.getIntValue());
		repDefine.setResourceId(sysResource.getResourceId());
		sysResourceRepository.save(sysResource);
		return new ResultMsg(true,"发布成功！");
	}
	

}